#8-10递归算阶乘
def fac(n):
    if n ==1:
        return 1
    else:
        return n*fac(n-1)
print(fac(5))
print('-'*50)
#8-11斐波那契数列
def fac(n):
    if n==1 or n==2:
        return 1
    else:
        return fac(n-1)+fac(n-2)

for i in range(1,10):
    print(fac(i),end='\t')
print()
print('-'*30)


#8-12 数据类型转换函数
print('非空字符串的布尔值:',bool('hello')) # True
print('空字符串的布尔值:',bool(''))  # 空字符串不是空格字符串
print('空列表的布尔值:',bool([]))
print('空列表的布尔值:',bool(list()))
print('空元组的布尔值:',bool(()))
print('空元组的布尔值:',bool(tuple()))
print('空集合的布尔值:',bool(set()))
print('空字典的布尔值:',bool({}))
print('空字典的布尔值:',bool(dict()))
print('-'*30)
print('非0数值型的布尔值:',bool(123))
print('整数0的布尔值:',bool(0))
print('浮点数0.0的布尔值:',bool(0.0))
# 将其它类型转成字符串类型
lst=[10,20,30]
print(type(lst),lst)

s=str(lst)
print(type(s),s)

# float类型和str类型转成int类型
print('-'*30,'float类型和str类型转成int类型','-'*30)
print(int(98.7)+int('90'))
# 注意事项
#print(int('98.7')) # ValueError: invalid literal for int() with base 10: '98.7'
#print(int('a')) # ValueError: invalid literal for int() with base 10: 'a'

print('-'*30,'int,str类型转成float类型','-'*30)
print(float(90)+float('3.14'))

s='hello'
print(list(s))

seq=range(1,10)
print(tuple(seq))
print(set(seq))
print(list(seq))
print('-'*30)

#8-13数学函数的使用
print(abs(100),abs(-100),abs(0))
print(divmod(13,4))
print(max('hello'))
print(min('hello'))
print(max([1,2,3,4,4,8]))
print(min([1,2,3,4,4,8]))
print(sum([10,20,30]))
print(pow(2,4))

print(round(3.1415926))
print(round(3.92388))
print(round(3.2131,3))
print(round(53.132324,-1))
print(round(3323.324,-2))
print('-'*40)

#8-14迭代器的使用
lst=[54,56,34,5,42,46,34]
#(1)排序
asc_lst=sorted(lst)
desc_lst=sorted(lst,reverse=True)
print('原列表：',lst)
print('升序：',asc_lst)
print('降序：',desc_lst)

#(2)reversed 反向
new_lst=reversed(lst)
print(type(new_lst))
print(list(new_lst))

#(3)zip
x=['a','b','c','d']
y=[10,20,30,40,50]
zipobj=zip(x,y)
print(type(zipobj))

#(4)enumerate
enum=enumerate(y,start=1)
print(type(enum)) # <class 'enumerate'>
print(tuple(enum))






